/*
 * DropTargetImpl.h
 *
 *  Created on: 2012-9-2
 *      Author: yangentao@gmail.com
 */

#pragma once;
#include <windows.h>
#include <ole2.h>
namespace yet{
IDropTarget* RegisterDropWindow(HWND hwnd);
void UnregisterDropWindow(HWND hwnd, IDropTarget *pDropTarget);

class DropTargetImpl: public IDropTarget {
public:
	DropTargetImpl(HWND hWnd);
	virtual ~DropTargetImpl();
public:
	ULONG STDMETHODCALLTYPE AddRef(void);
	ULONG STDMETHODCALLTYPE Release(void);
	HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppv);
public:
	HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObj,DWORD grfKeyState,POINTL pt,DWORD *pdwEffect);
	HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState,POINTL pt,DWORD *pdwEffect);
	HRESULT STDMETHODCALLTYPE DragLeave( void);
	HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObj,DWORD grfKeyState,POINTL pt,DWORD *pdwEffect);
private:
	DWORD DropEffect(DWORD grfKeyState, POINTL pt, DWORD dwAllowed);
	bool QueryDataObject(IDataObject *pDataObject);
private:

	HWND hWnd;
	bool allowDrop;
	volatile LONG refCount;
};

}
